<template>
  <div id="app">
    <header class="head">
      <a class="back tl" href="javascript:history.back(-1)">
        <i class="el-icon-arrow-left"></i>
      </a>
      <a href="javascript:;" class="tc">
        <small class="font_18 co_f">添加晨检</small>
      </a>
      <a href="javascript:;" class="save">
        <button @click="submitForm()" type="primary">保存</button>
      </a>
    </header>
    <main>
      <div class="formcontent" :rules="rules">
        <ul>
          <li>
            <span> <em>*</em>晨检日期</span>
            <div class="froms">{{datatime()|time}}</div>
          </li>
          <li>
            <span><em>*</em>晨检结果</span>
            <div class="froms">
              <el-select v-model="value" placeholder="请选择" name="value"  v-validate="'required'" :class="{'is-danger': errors.has('value')}">
                <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.label">
                </el-option>
              </el-select>
            </div>
          </li>
          <li>
            <span> <em>*</em> 姓名</span>
            <div class="froms">
              <input type="button" @click="handleClick" class="text_l" name="msg" v-model="msg" v-validate="'required'" :class="{'is-danger': errors.has('msg')}">
              <mt-popup v-model="popupVisible" position="right" modal=false class="mint-popup-3">
                <app-person v-on:listenToChildEvent="peopleClick" v-on:listencloseclick="clickmodl"></app-person>
              </mt-popup>
            </div>
          </li>
        </ul>
      </div>
    </main>
  </div>
</template>

<script>
  import Person from '@/components/institutionPerson'
  import {
    Popup
  } from 'mint-ui'
  import {
    MorningRecordAdd
  } from '../../api/api'
  export default {
    name: 'add_mrcj',
    components: {
      'mt-popup': Popup,
      'app-person': Person,
    },
    data() {
      return {
        msg: '',
        getNowFormatDate: null,
        people: this.$route.query.name,
        options: [{
          value: '√',
          label: '正常'
        }, {
          value: '△',
          label: '发热'
        }, {
          value: '⊙',
          label: '腹泻'
        }, {
          value: '﹟',
          label: '皮肤溃疡'
        }, {
          value: '※',
          label: '其他传染病'
        }, {
          value: '不在岗',
          label: '不在岗位'
        }],
        value: '',
        CriteriaList: [],
        //组件
        seachtext: '',
        popupVisible: false,
        closeOnClickModal: false,
        getPerson: [],
        Enterprise: {},
        PageSize: 10,
        institutionPersonname: '',
        institutionPersonunid: '',
        showAlert: false, //弹出框
      };
    },
    computed: {
      errors() {
        return this.$verify.$errors
      }
    },
    methods: {
      handleClick: function() {
        this.popupVisible = true
      },
      clickmodl: function() {
        this.popupVisible = false
      },
      //获取item
      peopleClick: function(data) {
        this.institutionPersonname = data.name;
        this.institutionPersonunid = data.unid;
        this.clickmodl();
        this.msg = this.institutionPersonname
      },
      //获取当前时间
      datatime: function() {
        var moment = require('moment');
        var currentdate = moment().format('YYYY-MM-DD 00:00:00');
        return currentdate;
      },
      //提交方法
      submitForm: function() {
        debugger
        this.$validator.validateAll().then((result) => {
          if (result) {
            let varQueryData = {
              Name: this.institutionPersonname,
              Unid: this.institutionPersonunid,
            }
            let data = {
              MorningRecordDate: this.datatime(),
              MorningRecordContent: this.value,
              EnterprisePerson: varQueryData,
            }
            let dataoption = {
              params: {
                Data: JSON.stringify(data),
                UserUnid: JSON.parse(localStorage.getItem('auth')).UserUnid,
             //   Username:JSON.parse(localStorage.getItem('auth')).loginname,
              }
            }
            //调取接口
            MorningRecordAdd(dataoption).then((res) => {
              if (res.success === true) {
                this.$message.success('保存成功');
                this.$router.go(-1);
              } else {
                this.$message.error(res.msg);
              }
            }).catch(function() {
              this.$message.error('网络异常。');
            })
          } else {
            this.$message.error('带*号为必填项，请确认填写格式正确');
          }
        })
  
  
  
      },
      created() {
  
      },
    }
  }
</script>

<style lang="scss">
  
</style>
